
$(function () {
    map();
    function map() {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('map'));
var data = [
    {name:"新疆",value:100},
    {name:"西藏",value:100},
    {name:"黑龙江",value:100},
    {name:"吉林", value:100},
    {name:"辽宁", value:100},
    {name:"内蒙古",value:100},
    {name:"北京",value:100},
    {name:"宁夏",value:100},
    {name:"山西", value:100},
    {name:"河北",value:100},
    {name:"天津",value:100},
    {name:"青海",value:100},
    {name:"甘肃",value:100},
    {name:"山东",value:100},
    {name:"陕西",value:100},
    {name:"河南",value:100},
    {name:"安徽",value:100},
    {name:"江苏",value:100},
    {name:"上海",value:100},
    {name:"四川",value:100},
    {name:"湖北",value:100},
    {name:"浙江",value:100},
    {name:"重庆",value:100},
    {name:"湖南",value:100},
    {name:"江西",value:100},
    {name:"贵州",value:100},
    {name:"福建",value:100},
    {name:"云南",value:100},
    {name:"台湾",value:100},
    {name:"广西",value:100},
    {name:"广东",value:100},
    {name:"海南",value:100},
    {name:"澳门",value:100},
    {name:"香港",value:100},
];
var geoCoordMap = {
    "新疆": [86.61 , 40.79],
    "西藏":[89.13 , 30.66],
    "黑龙江":[128.34 , 47.05],
    "吉林":[126.32 , 43.38],
    "辽宁":[123.42 , 41.29],
    "内蒙古":[112.17 , 42.81],
    "北京":[116.40 , 40.40 ],
    "宁夏":[106.27 , 36.76],
    "山西":[111.95,37.65],
    "河北":[115.21 , 38.44],
    "天津":[117.04 , 39.52],
    "青海":[97.07 , 35.62] ,
    "甘肃":[103.82 , 36.05],
    "山东":[118.01 , 36.37],
    "陕西":[108.94 , 34.46],
    "河南":[113.46 , 34.25],
    "安徽":[117.28 , 31.86],
    "江苏":[120.26 , 32.54],
    "上海":[121.46 , 31.28],
    "四川":[103.36 , 30.65],
    "湖北":[112.29 , 30.98],
    "浙江":[120.15 , 29.28],
    "重庆":[107.51 , 29.63],
    "湖南":[112.08 , 27.79],
    "江西":[115.89 , 27.97],
    "贵州":[106.91 , 26.67],
    "福建":[118.31 , 26.07],
    "云南":[101.71 , 24.84],
    "台湾":[121.01 , 23.54],
    "广西":[108.67 , 23.68],
    "广东":[113.98 , 22.82],
    "海南":[110.03 , 19.33],
    "澳门":[113.54 , 22.19],
    "香港":[114.17 , 22.32]
};
var convertData = function (data) {
    var res = [];
    for (var i = 0; i < data.length; i++) {
        var geoCoord = geoCoordMap[data[i].name];
        if (geoCoord) {
            res.push({
                name: data[i].name,
                value: geoCoord.concat(data[i].value)
            });
        }
    }
    console.log(res)
    return res;
};

option = {
    tooltip : {
        trigger: 'item',
        formatter (value){
            return value.data.name + value.data.value[2]
        }
    },
  
    geo: {
        map: 'china',
        label: {
            emphasis: {
                show: false
            }
        },
        roam: false,
		zoom:1.2,
        itemStyle: {
            normal: {
                areaColor: 'rgba(2,37,101,.5)',
                borderColor: 'rgba(112,187,252,.5)'
            },
            emphasis: {
                areaColor: 'rgba(2,37,101,.8)'
            }
        }
    },
    series : [
        {
//            name: '标题名称',
            type: 'scatter',
            coordinateSystem: 'geo',
            data: convertData(data),
            symbolSize: function (val) {
                return val[2] / 15;
            },
            label: {
                normal: {
                    formatter: '{b}',
                    position: 'right',
                    show: false
                },
                emphasis: {
                    show: true
                }
            },
            itemStyle: {
                normal: {
                    color: '#ffeb7b'
                }
            }
        }

    ]
};
		
        myChart.setOption(option);
        window.addEventListener("resize",function(){
            myChart.resize();
        });
    }

})

